package net.board.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.board.db.BoardDAO;
import net.board.db.BoardBean;

 public class BoardDetailAction implements Action {
	 public ActionForward execute(HttpServletRequest request,HttpServletResponse response) throws Exception{ 

		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
   		
		BoardDAO boarddao=new BoardDAO();
	   	BoardBean boarddata=new BoardBean();
	   	
		int ID=Integer.parseInt(request.getParameter("ID"));
		System.out.println("넘어오는번호(2):"+request.getParameter("number"));
		
		int number = Integer.parseInt(request.getParameter("number"));
		String url;
		
		boarddao.setReadCountUpdate(ID);
	   	boarddata=boarddao.getDetail(ID);
	   	
	   	if(boarddata==null){
	   		return null;
	   	}
	   	
	   	if(number == 1){
	   		url = "/Main/OldMain/Om_Main.jsp";
	   	}else if(number == 3){
	   		url = "/Main/admin/Ad_Main.jsp";
	   	}
	   	else{
	   		url = "/Main/YoungMain/Ym_Main.jsp";
	   	}
	   	
	   	System.out.println("접속자 레벨 = " + number);

	   	String pagename = "/board/qna_board_view";
		request.setAttribute("page", pagename);
	   	request.setAttribute("boarddata", boarddata);
	   	request.setAttribute("number", number);
	   	ActionForward forward = new ActionForward();
	   	forward.setRedirect(false);
   		forward.setPath(url);
   		return forward;

	 }
}